<?php
include("../mysqlcon.php");
mysql_select_db($dbname,$conn);
mysql_query('SET NAMES utf8');
//$reserv_id = $_GET[reserv_id];
$current = date("Y-m-d",strtotime("Today"));

$keyValidate = null;
if($_GET['reserv_gid'] != null){
	$temp = $_GET['reserv_gid'];
	$keyValidate = 'reservgroup.reserv_gid = '.$temp;
}elseif($_GET['customer_name'] != null){
	$temp = $_GET['customer_name'];
	$keyValidate = "customer.customer_name LIKE '%".$temp."%'";
}elseif($_GET['customer_surname'] != null){
	$temp = $_GET['customer_surname'];
	$keyValidate = "customer.customer_surname LIKE '%".$temp."%'";
}
/*$validatesql = "SELECT reserv_id,reserv_begin,reserv_end,room_id,customer.customer_id,customer.id,customer_name,customer_surname,customer_email,customer_tel,customer_fax FROM reservation,customer 
WHERE reserv_begin = '$current' AND reserv_id = '$reserv_id' AND reservation.id = customer.id AND reserv_status = '1'";*/

$validatesql = "SELECT reserv_id,reserv_begin,reserv_end,room_id,customer.customer_id,customer.id,customer_name,customer_surname,customer_email,customer_tel,customer_fax,reservgroup.reserv_gid,reservgroup.room_list 
				FROM reservation
				INNER JOIN reservgroup ON ( reservation.reserv_gid = reservgroup.reserv_gid )
				INNER JOIN customer ON ( reservation.id = customer.id ) 
				WHERE $keyValidate AND reserv_status < '4' GROUP BY reserv_gid";
	$r = mysql_query($validatesql,$conn);
	echo "[";
	while ($rs = mysql_fetch_array($r))
	{
		$temp_gid = $rs['reserv_gid'];
		$validatesql = "SELECT reserv_id,reserv_begin,reserv_end,resort.room_id,roomsize_name,roomtype_name,room_cost,customer.customer_id,customer.id,customer_name,customer_surname,customer_email,customer_tel,customer_fax,reservgroup.reserv_gid,reservgroup.room_list 
				FROM reservation
				INNER JOIN reservgroup ON ( reservation.reserv_gid = reservgroup.reserv_gid )
				INNER JOIN customer ON ( reservation.id = customer.id )
				INNER JOIN resort ON ( reservation.room_id = resort.room_id )
				INNER JOIN roomsize ON ( resort.roomsize_id = roomsize.roomsize_id )
				INNER JOIN roomtype ON ( resort.roomtype_id = roomtype.roomtype_id )  
				WHERE reservgroup.reserv_gid = '$temp_gid' AND reserv_status < '4'";
		$r_checkin = mysql_query($validatesql,$conn);
		echo "[";
		while ($rs_checkin = mysql_fetch_array($r_checkin))
		{
	   		if($current != $rs_checkin['reserv_begin']){
	      		$rs_checkin['reserv_begin'] = '<b style="color:red;">' . $rs_checkin['reserv_begin'] . '</b>';}
	      		
	   		echo "{reserv_id: '".$rs_checkin['reserv_id']."',reserv_gid: '".$rs_checkin['reserv_gid']."', reserv_begin: '".$rs_checkin['reserv_begin']."', reserv_end: '".$rs_checkin['reserv_end']."', 
	   		       room_id: '".$rs_checkin['room_id']."', roomsize_name: '".$rs_checkin['roomsize_name']."', roomtype_name: '".$rs_checkin['roomtype_name']."',room_cost: '".$rs_checkin['room_cost']."',room_list: '".$rs_checkin['room_list']."', 
	   			   customer_id: '".$rs_checkin['customer_id']."', cid: '".$rs_checkin['id']."', customer_name: '".$rs_checkin['customer_name']."', customer_surname: '".$rs_checkin['customer_surname']."', customer_email: '".$rs_checkin['customer_email']."', customer_tel: '".$rs_checkin['customer_tel']."', customer_fax: '".$rs_checkin['customer_fax']."'}, ";
		}
		echo "],";
	   /*if(($check != $rs[reserv_gid]) && ($check != "")){
	   	echo "],[";
	   }
	   $check = $rs[reserv_gid];*/
	   
	}
	echo "]";
?>
